<html>
<head>
<title>Spell Now</title>

<style>
INPUT,TEXTAREA {
		font-family: serif;
		font-size: 32px;
		text-align: center;
	}

body {
		text-align: center;
		font-family: serif;
		font-size: 22px;
	}


p {
		font-family: serif;
		font-size: 22px;
	}
</style>
<script src="configuration/wordlist-06.js"></script>
<script type="text/javascript" src="script/soundmanager.js"></script>

<script>

document.word.letter1.value="1"

var correct = 0
var incorrect = 0
var missing1 = ""
var field1 = ""
var wordlength = 0
var rand1 = -1
var arrayLength = 0
var wordList = ""
var count = 0

function readCookie(name) {
				var nameEQ = name + "=";
				var ca = document.cookie.split(';');
				for(var i=0;i < ca.length;i++) {
					var c = ca[i];
					while (c.charAt(0)==' ') c = c.substring(1,c.length);
						if (c.indexOf(nameEQ) == 0)
					if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
				}
				return null;
			}

function newWord() {
	for (i=0; i<arrayLength; i++) {
		//document.word.getElementById[i].disabled=true;
	}

	// This is just to clear form fields, just in case
	for (i=0; i<arrayLength; i++) {
			document.word.getElementById[i].value=""
	}
	// End of needing to clear form fields

	rand1 = rand1 + 1
	wordlength = words[rand1].length
	rand2 = Math.floor(Math.random()*wordlength)

	var aryText = new Array()

	for (i = 0; i < wordlength; i++) {
		aryText[i] = words[rand1].charAt(i)
	}

	for (i=0; i<words[rand1].length; i++) {
		if (i == rand2) {
			document.word.elements[i].disabled=false;
			missing1 = i
		}
		else {
			document.word.elements[i].disabled=true;
			document.word.elements[i].value = aryText[i]
		}
	}

	field1 = aryText[missing1]

	document.word.elements[rand2].focus();
	document.word.hint.disabled=false
	document.word.hint.value = def[rand1]

	soundManager.play(words[rand1])

	count = count - 1

	if (count < 1) {
		finish();
	}

}

function enteredWord() {
	if (document.word.elements[missing1].value == field1) {
		correct = correct + 1
		document.word.correct.value = correct
		newWord()
	} else {
		incorrect = incorrect + 1
		document.word.incorrect.value = incorrect
		newWord()
	}
}

function pageLoad() {
	wordList = readCookie("list")
	arrayLength = words.length
	count = arrayLength
	newWord()
}

function finish() {
	var total = correct + incorrect
	var score = correct / total
	alert("Completed! Your score is: " + score + "!")
}

</script>
</head>
<body onLoad="pageLoad()">

<div>
<script type="text/javascript">soundManagerInit();</script>
</div>

<p>Practise your spelling!</p>
	<form name="word">
		<input type="text" name="letter0" size="1" maxlength="1" onKeyUp="enteredWord()">
		<input type="text" name="letter1" size="1" maxlength="1" onKeyUp="enteredWord()">
		<input type="text" name="letter2" size="1" maxlength="1" onKeyUp="enteredWord()">
		<input type="text" name="letter3" size="1" maxlength="1" onKeyUp="enteredWord()">
		<input type="text" name="letter4" size="1" maxlength="1" onKeyUp="enteredWord()">
		<input type="text" name="letter5" size="1" maxlength="1" onKeyUp="enteredWord()">
		<input type="text" name="letter6" size="1" maxlength="1" onKeyUp="enteredWord()">
		<br><br>
		<input type="text" name="hint" size="45" maxlength="45">
		<br><br>
		Correct: <input type="text" name="correct" size="1" maxlength="3" style="background: yellow;">  Incorrect: <input type="text" name="incorrect" size="1" maxlength="3" style="background: lightgreen;">
		<br><br>
	</form>


</body>
</html>
